<extend name="common:base" />
<block name="content">
    <div id="header">
        <div class="header">
            <h1 class="tit">{$site_title}</h1>
            <!--<p class="goback">-->
                <!--<a class="return" href="{:U('Setting/agent_address')}">返回</a>-->
            <!--</p>-->
            <!--<p class="more"><a class="share" href=""></a></p>-->
        </div>
    </div>
    <div class="person-msg">
        <div class="person-top">
            <p class="address_list">
                <span class="fleft ltitle">收货人</span>
                <input type="text" class="txt" id="adress_u" value="{$address['consignee']}"/>
            </p>
            <p class="address_list">
                <span class="fleft ltitle">联系电话</span>
                <input type="number" class="txt" id="mobile" value="{$address['mobile']}"/>
                            </p>


            <p class="address_list" data-toggle="distpicker">
            <span class="fleft ltitle">所选地区</span>
                <select id="provice" data-province="{$address['province']}"></select>
                <select id="city" data-city="{$address['city']}"></select>
                <select id="area" data-district="{$address['area']}"></select>
            </p>


            <textarea placeholder="详细地址" id="detail_address">{$address['detail_address']}</textarea>
        </div>
    </div>
    <div class="person-form"><span id="add_btn">保存</span></div>
</block>
<block name="CSS">
    <link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/agentview.css" />
    <style>
        .address_list select {
            width: 19%;
            float: left;
        }
        #area {
           float: right;
        }
    </style>
</block>
<block name="JS">
    <script type="text/javascript" src="__PUBLIC__/Admin/static/distpicker/js/distpicker.data.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Admin/static/distpicker/js/distpicker.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Admin/static/distpicker/js/main.js"></script>
    <script type="text/javascript">
        $(function(){
            $("#add_btn").click(function() {
                var adress_u = $("#adress_u").val();
                var mobile = $("#mobile").val();
                var detail_address = $("#detail_address").val();
                if(!adress_u || !mobile || !detail_address){
                    layer.msg("信息填写不完整", {time:800});
                    return false;
                }
                var reg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
                if(!reg.test(mobile)) {
                    layer.msg('请填写有效的手机号码！', {time:800});
                    return false;
                }

                var provice = $('#provice').val();
                var city = $('#city').val();
                var area = $('#area').val();
                if (provice == '') {
                    layer.msg('请填写选择地区！', {time:800});
                    return false;
                }

                $.ajax({
                    url: "{:U('Setting/edit_address')}",
                    type: 'post',
                    data:{
                        address_id: "{$address['address_id']}",
                        get_user: adress_u,
                        tel: mobile,
                        addre: detail_address,
                        provice: provice,
                        city: city,
                        area: area
                    },
                    success:function (data) {
                        if(data.status == "success"){
                            window.location.href = "{:U('Setting/agent_address')}";
                        }else{
                            layer.msg(data.msg ,{time:800});
                        }
                    }
                });
            });
        });
    </script>
</block>
